﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EFJson;
using System.Threading;

namespace PlantHire.Controllers
{
    public class AjaxController : Controller
    {
        private PlantHireEntities db = new PlantHireEntities();
        //
        // GET: /Ajax/

        public String Index()
        {
            return "Hey yo!";
        }

        //
        // POST: /Ajax/GetAllSubcategory
        [HttpPost]
        public JsonResult GetAllSubcategory(int data = 0)
        {
            JsonResult json = new JsonResult();
            var result = db.Subcategories.Where(s => s.PlantTypeId == data).ToList().Select(c => JsonHelper.ConvertToSimpleObject(c));
            json.Data = result;
            Thread.Sleep(2000); // Give it some delay to show "Loading..." text.
            return json;
        }

        //
        // POST: /Ajax/GetAllSizeModel
        [HttpPost]
        public JsonResult GetAllSizeModel(int data = 0)
        {
            JsonResult json = new JsonResult();
            var result = db.SizeModels.Where(s => s.SubcategoryId == data).ToList().Select(c => JsonHelper.ConvertToSimpleObject(c));
            json.Data = result;
            Thread.Sleep(500); // Give it some delay to show "Loading..." text.
            return json;
        }


    }
}
